import Vue from "vue";
import VueRouter from "vue-router";
import Home from "../views/Home.vue";

Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    component: Home,
    meta: {
      title: '大厂车检'
    },
  },
  {
    path: '*',
    redirect: '/',
    meta: {
      title: '大厂车检'
    },
  },

  // 个人中心
  {
    meta: {
      title: '个人中心'
    },
    name: 'personalCenter',
    path: "/personalCenter",
    component: () => import("../views/personalCenter/index.vue")
  },
  // 预约检测
  {
    meta: {
      title: '预约检测'
    },
    name: 'makeAnAppointment',
    path: "/makeAnAppointment",
    component: () => import("../views/MakeAnAppointment/index.vue")
  },
  // 到场检测 -  添加车辆
  {
    meta: {
      title: '选择车辆'
    },
    name: 'vehicleInfo',
    path: "/vehicleInfo",
    component: () => import("../views/vehicleInfo/index.vue")
  },
  // 到场检测 - 添加车辆 - 详情
  {
    meta: {
      title: '添加车辆信息'
    },
    name: 'vehicleDetails',
    path: "/vehicleDetails",
    component: () => import("../views/vehicleInfo/details.vue")
  },
  // 到场检测 - 添加车辆 - 选择监测站
  {
    meta: {
      title: '选择监测站'
    },
    path: "/vehicleDetection",
    component: () => import("../views/vehicleInfo/detection.vue")
  },
  // 打印单据
  {
    meta: {
      title: '自助打印单据'
    },
    path: "/printDocuments",
    component: () => import("../views/PrintDocuments/index.vue")
  },
  // 打印单据 - 详情
  {
    meta: {
      title: '打印单据详情'
    },
    name: 'printDetails',
    path: "/printDetails",
    component: () => import("../views/PrintDocuments/details.vue")
  },
  // 订单
  {
    meta: {
      title: '订单详情'
    },
    name: 'order',
    path: "/order",
    component: () => import("../views/order/index.vue")
  },
  // 支付
  {
    meta: {
      title: '支付'
    },
    name: 'orderPay',
    path: "/orderPay",
    component: () => import("../views/OrderPay/index.vue")
  },
  // 订单进度
  {
    meta: {
      title: '订单进度'
    },
    name: 'progress',
    path: "/progress",
    component: () => import("../views/progress/index.vue")
  },
  // 服务协议
  {
    meta: {
      title: '服务协议'
    },
    name: 'agreement',
    path: "/vehicleAgreement",
    component: () => import("../views/vehicleInfo/agreement.vue")
  },
  //年检须知
  {
    meta:{
      title: '年检须知'
    },
    name: 'notice',
    path: '/notice',
    component:() => import('../views/Notice/index.vue')
  },
  //年检流程
  {
    meta:{
      title: '年检流程'
    },
    name: 'inspectionProcess',
    path: '/inspectionProcess',
    component:() => import('../views/inspectionProcess/index.vue')
  },
  //预约流程
  {
    meta:{
      title: '预约流程'
    },
    name: 'reservationProcess',
    path: '/reservationProcess',
    component:() => import('../views/reservationProcess/index.vue')
  },
  //电子单据
  {
    meta:{
      title: '电子单据'
    },
    name: 'electronicOrder',
    path: '/electronicOrder',
    component:() => import('../views/electronicOrder/index.vue')
  },
  //pdf 电子单据收据
  {
    meta:{
      title: '浏览电子单据'
    },
    name: 'pdf',
    path: '/pdf',
    component:() => import('../views/electronicOrder/pdf.vue')
  },
  //服务评价
  {
    meta:{
      title: '服务评价'
    },
    name: 'serviceRating',
    path: '/serviceRating',
    component:() => import('../views/serviceRating/index.vue')
  },
  //开具发票
  {
    meta:{
      title:'开具发票'
    },
    name:'invoice',
    path:'/invoice',
    component:() => import('../views/invoice/index.vue')
  },
  //问卷调查
  {
    meta:{
      title:'问卷调查'
    },
    name:'questionnaire',
    path:'/questionnaire',
    component:() => import('../views/questionnaire/index.vue')
  },
  //综检
  {
    meta:{
      title:'综检'
    },
    name:'comprehensiveInspection',
    path:'/comprehensiveInspection',
    component:() => import('../views/comprehensiveInspection/index.vue')
  },
  //其他类别检测
  {
    meta:{
      title:'其他类别检测'
    },
    name:'other',
    path:'/other',
    component:() => import('../views/other/index.vue')
  },
  //订单详情
  {
    meta:{
      title:'订单详情'
    },
    name:'orderDetails',
    path:'/orderDetails',
    component:() => import('../views/order/orderDetails.vue')
  },
  //申请退费
  {
    meta:{
      title:'申请退费'
    },
    name:'refund',
    path:'/refund',
    component:() => import('../views/order/refund.vue')
  },
  //六年免检
  {
    meta:{
      title:'六年免检'
    },
    name:'inspectionFree',
    path:'/inspectionFree',
    component:() => import('../views/InspectionFree/index.vue')
  },
  //挂车
  {
    meta:{
      title:'挂车'
    },
    name:'truck',
    path:'/truck',
    component:() => import('../views/truck/index.vue')
  },
  //车辆信息
  {
    meta:{
      title:'车辆信息'
    },
    name:'mycar',
    path:'/mycar',
    component:() => import('../views/myCar/index.vue')
  },
  //帮助中心
  {
    meta:{
      title:'帮助中心'
    },
    name:'helpCenter',
    path:'/helpCenter',
    component:() => import('../views/personalCenter/helpCenter.vue')
  },
  //贵宾卡列表
  {
    meta:{
      title:'贵宾卡'
    },
    name:'vip',
    path:'/vip',
    component:() => import('../views/vip/index.vue')
  }
];

const router = new VueRouter({
  mode: "history",
  base: process.env.BASE_URL,
  routes
});

router.afterEach(route => {
  // 从路由的元信息中获取 title 属性
  if (route.meta.title) {
    document.title = route.meta.title;
    // 如果是 iOS 设备，则使用如下 hack 的写法实现页面标题的更新
    if (navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)) {
      const hackIframe = document.createElement('iframe');
      hackIframe.style.display = 'none';
      hackIframe.src = '/static/html/fixIosTitle.html?r=' + Math.random();
      document.body.appendChild(hackIframe);
      setTimeout(_ => { 
        document.body.removeChild(hackIframe)
      }, 300)
    }
  }
})
export default router;
